package com.wabbei.friendcenter.action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Date;

import org.apache.struts2.ServletActionContext;

import com.webbei.friendcenter.service.MyFriendCenter;
import com.webbei.pojo.Messages;

public class SwfSuccessToDateBase {
		private String toName;
		private String filesName;
		private String messageContent;
		private MyFriendCenter friservice;
		private InputStream inputstream=null;
		private String[] spiltFilesName;
		private Messages message;
		private Date date;


		public InputStream getInputstream() {

			String result="true";
			String fromName =(String)ServletActionContext.getContext().getSession().get("username");

			date=new Date();
			message=new Messages();
			message.setFromName(fromName);
			message.setToName(toName);
			message.setMessageTime(date);
			message.setMessageContent(messageContent);
			if(filesName!=null&&!filesName.equals("")){
				spiltFilesName=filesName.split(",");
				for(String s:spiltFilesName){
					if(s.endsWith("txt")){
						message.setCDRfilePath(s);
					}else{
						message.setMessagePic(s);
					}
				}
			}else{
				message.setCDRfilePath("");
				message.setMessagePic("");
			}

			int i=friservice.insertMessageEachOther(message);
			if(i>0){
				result="true";
			}else{
				result="false";
			}
			inputstream=new ByteArrayInputStream(result.getBytes());
			return inputstream;
		}
		public void setInputstream(InputStream inputstream) {
			this.inputstream = inputstream;
		}
		public Date getDate() {
			return date;
		}
		public void setDate(Date date) {
			this.date = date;
		}
		public Messages getMessage() {
			return message;
		}
		public void setMessage(Messages message) {
			this.message = message;
		}
		public MyFriendCenter getFriservice() {
			return friservice;
		}
		public void setFriservice(MyFriendCenter friservice) {
			this.friservice = friservice;
		}
		public String getToName() {
			return toName;
		}
		public void setToName(String toName) {
			this.toName = toName;
		}
		public String getFilesName() {
			return filesName;
		}
		public void setFilesName(String filesName) {
			this.filesName = filesName;
		}
		public String getMessageContent() {
			return messageContent;
		}
		public void setMessageContent(String messageContent) {
			this.messageContent = messageContent;
		}
		public String check(){
			return "success";
		}

}
